/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package avl.sv.shared;

import avl.sv.shared.Annotations.ROI;
import java.util.ArrayList;
import javax.swing.tree.TreePath;
import org.jdesktop.swingx.JXTreeTable;

/**
 *
 * @author benbryan
 */
public class JXTreeTableROIs extends JXTreeTable {

    public void setSelectionPaths(ArrayList<TreePath> paths) {
        getSelectionModel().clearSelection();
        for (TreePath path : paths) {
            setSelectionPath(path);
        }
    }

    public void setSelectionPath(TreePath path) {
        if (path.getLastPathComponent() instanceof ROI) {
            expandPath(path.getParentPath());
        }
        int r = getRowForPath(path);
        getSelectionModel().addSelectionInterval(r, r);
    }
    
    public TreePath[] getSelectionPaths(){
        int[] rows = getSelectedRows();
        TreePath paths[] = new TreePath[rows.length];
        for (int rIdx = 0; rIdx < rows.length; rIdx++) {
            paths[rIdx] = getPathForRow(rows[rIdx]);
        }
        return paths;
    }
    
    public TreePath getSelectionPath(){
        int row = getSelectedRow();
        return getPathForRow(row);
    }

    Object getLastSelectedPathComponent() {
        return getSelectionPath().getLastPathComponent();
    }
    
}
